package cn.zhanghu;


/**
 * Created by dell on 2017/7/4.
 */
public class SortArray {
    public static int[] mergeArray(int[] arrayA, int[] arrayB) {
        int[] temp = new int[arrayA.length+arrayB.length];
        int i = 0;
        int j = 0;
        int k = 0;
        while (i <arrayA.length&& j <arrayB.length) {
            if (arrayA[i] > arrayB[j]) {
                temp[k++] = arrayB[j++];
            }
            else{
                temp[k++]=arrayA[i++];
            }
        }
        while(i<arrayA.length){
            temp[k++]=arrayA[i++];
        }
        while(j<arrayB.length){
            temp[k++]=arrayB[j++];
        }
        while(i<j) {
            temp[i] = temp[i++];
        }
        //int[] value=temp;
       //for(int m=0;m<temp.length;m++){
           // System.out.print(" "+temp[m]+"");
        //}
        //for(int value:temp){
            //System.out.println(" "+value+"");
        //}
        return temp;
    }
    public static void result(int[] temp){
        for(int value:temp){
            System.out.print(""+value+" ");
        }
    }
    public static void main(String[] args){
        int[] array1=new int[]{2,4,5,8,10,55,56,67,659};
        int[] array2=new int[]{1,3,5,7,9,43,53,89,99,100};
        int[] temp=SortArray.mergeArray(array1,array2);
        result(temp);
    }
}


